﻿using Hotel.Model;

namespace Hotel.DAL
{
    public class LoginDAL
    {
        public LoginDAL(MyContext myContext)
        {
            MyContext = myContext;
        }

        public MyContext MyContext { get; }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public int Add(Login login)
        {
            try
            {
                MyContext.logins.Add(login);
                return MyContext.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Login Login(string name)
        {
            try
            {
                return MyContext.logins.FirstOrDefault(x => x.Name == name);
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}